package com.sun.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.sun.draw.pojo.InstantDrawInfo;

/**
 * 抽奖工具类
* @ClassName: DrawUtils  
* @author sunt  
* @date 2018年1月11日 
* @version V1.0
 */
public class DrawUtils {

	/**
	 * 根据抽奖策略计算中奖概率范围
	* @Title: getProbabilityRange 
	* @author sunt  
	* @date 2018年1月11日
	* @return List<Double>
	 */
	public static List<Double> getProbabilityRange(List<InstantDrawInfo> list) {
		List<Double> resList = null;
		if (list != null && list.size() > 0) {
			resList = new ArrayList<Double>();
			// 设置最小边界值
			double tmpValue = 0.0;
			resList.add(tmpValue);

			for (int i = 0; i < list.size(); i++) {
				InstantDrawInfo instantDrawInfo = list.get(i);
				if (null == instantDrawInfo) {
					continue;
				}
				
				tmpValue += instantDrawInfo.getPrizeProbability().doubleValue();
				resList.add(tmpValue/100);
			}
		}
		return resList;
	}
	
	/**
	 * 按照抽奖概率排序
	* @Title: sortByProbabilityAsc 
	* @author sunt  
	* @date 2018年1月12日
	* @return void
	 */
	public static void sortByProbabilityAsc(List<InstantDrawInfo> list) {
		if (null != list && list.size() > 0) {
			Collections.sort(list, new Comparator<InstantDrawInfo>() {
				public int compare(InstantDrawInfo o1, InstantDrawInfo o2) {
					if ((null != o1) && (null != o2)) {
						if (o1.getPrizeProbability().compareTo(o2.getPrizeProbability()) == 1) {
							return 1;
						}
					}
					return 0;
				}
			});
		}
	}
}
